package top.frsf;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.awt.*;

/**
 * @BelongsProject: MiniPZ
 * @BelongsPackage: top.frsf
 * @Author: FRSF
 * @CreateTime: 2022-09-06  14:32
 * @Description: 游戏元素父类
 * @Version: 1.0
 */

@Data
public class GameObject {
    // 基础属性
    private int x;
    private int y;
    private int width;
    private int height;

    // 图像
    private Image img;

    public GameObject(String img, int x, int y, int width, int height) {
        this.x = x;
        this.y = y;
        this.width = width;
        this.height = height;
        this.img = Toolkit.getDefaultToolkit().getImage(img);
    }

    /* 元素自身绘制 */
    public void paintSelf(Graphics g) {
        g.drawImage(img, x, y, null);
    }

    /* 矩形面积返回 */
    public Rectangle getRec() {
        return new Rectangle(x, y, width, height);
    }
}
